<?php

namespace app\index\service;

use app\common\model\LawCaseCategory;
use app\common\model\Member;

/**
 *
 * Class AdInfoService
 * @package app\index\service
 */
class AdInfoService
{

    /**
     * @return array
     */
    public function read(): array
    {

        $table = Member::getTable();

        $lawyers = Member::leftJoin('member_info mi', "$table.id=mi.memberId")
            ->where('status', '1')
            ->where('type', '1')
            ->where('checkStatus', '1')
            ->where('muted', '0')
            ->where('medal', '1')
            ->where('followedWechat', '1')
            ->tableField(['id', 'nickname', 'realname', 'type', 'headImgUrl', 'cropImgUrl'], $table)
            ->with([
                'memberInfo' => fn($subQuery) => $subQuery->field([
                    'memberId',
                ])->with([
                    'categories' => fn($query) => $query->shortCategory(),
                ])
            ])
            ->append(['headImgThumb', 'cropImg', 'showName'])
            ->hidden(['headImgUrl'])
            ->order('matchStatus', 'DESC')
            ->limit(3)
            ->select();

        // 案件类型
        $categories = LawCaseCategory::field(true)->append(['smallPicImgMin'])->select();

        $data = [
            'lawyers' => $lawyers,
            'categories' => $categories,
        ];

        return $data;
    }
}
